package com.example.mystoryapp2.contexts

import android.app.Application
import com.example.mystoryapp2.data.sp.SpUtils
import com.example.mystoryapp2.domain.UserInfo

object AppContext {
    var userInfo: UserInfo = UserInfo()
    lateinit var application: Application
    var jwt: String?

    init {
        this.jwt = SpUtils.getStringValue(SpUtils.JWT)
    }

    fun saveUserInfo(userInfo: UserInfo) {
        this.userInfo = userInfo
    }

    fun saveJwt(jwt: String?) {
        this.jwt = jwt
        if (jwt != null) {
            SpUtils.setValue(SpUtils.JWT, jwt)
        }
    }

    fun clearJwt() {
        this.jwt = ""
        SpUtils.clearValue(SpUtils.JWT)
    }

    fun isAuthor(): Boolean {
        return userInfo.isAuthor();
    }
}